//
//  LYPickerComponent.h
//  PickerDemo
//
//  Created by 李阳 on 2018/4/17.
//  Copyright © 2018年 李阳. All rights reserved.
//

#import <UIKit/UIKit.h>

/// 列模型基类
@interface LYColumnItem : NSObject
/// 列号
@property (nonatomic, assign, readonly) NSInteger columnIndex;
@end

#pragma mark -
/// 列样式模型
@interface LYColumnStyle : LYColumnItem

/// 选中字体颜色
@property (nonatomic, strong) UIColor *selectedTextColor;
/// 文字对其方式，默认居中，优先级大于`PickerView`中的`textAlignment`
@property (nonatomic, assign) NSTextAlignment textAlignment;
/// 字体
@property (nonatomic, strong) UIFont *font;
/// 列宽
@property (nonatomic, assign) CGFloat widthRatio;
/// 行高
@property (nonatomic, assign) CGFloat rowHeight;

@end


#pragma mark -
/// 选择器基类
@interface LYPickerView : UIPickerView

/// 行高
@property (nonatomic, assign) CGFloat rowHeight;
/// 分割线颜色
@property (nonatomic, strong) UIColor *seperatorColor;
/// 选中字体颜色
@property (nonatomic, strong) UIColor *selectedTextColor;
/// 选中行的背景颜色
@property (nonatomic, strong) UIColor *selectedBackgroundColor;
/// 字体
@property (nonatomic, strong) UIFont *font;
/// 文字对其方式，
@property (nonatomic, assign) NSTextAlignment textAlignment;

/// 列样式模型数组
@property (nonatomic, strong) NSArray<LYColumnStyle *> *styles;


/// 如果needed为yes 会回调代理 -pickerView:didSelectRow:inComponent:方法
- (void)selectRow:(NSInteger)row
      inComponent:(NSInteger)component
         animated:(BOOL)animated
     needCallback:(BOOL)needed;

#pragma mark Subclass Override
- (void)setup;

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingLabel:(UILabel *)label title:(NSString *)title;
- (CGFloat)widthForComponent:(NSInteger)component;
- (CGFloat)rowHeightForComponent:(NSInteger)component;
- (NSString *)titleForRow:(NSInteger)row forComponent:(NSInteger)component;
- (void)didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
/// 加个total是为了区分系统的方法
- (NSInteger)numberOfComponentsTotal;
- (NSInteger)numberOfRowsInComponent:(NSInteger)component;
@end


#pragma mark -
/// 列数据模型
@interface LYColumnData : LYColumnItem

/// 该列数据
@property (nonatomic, strong) NSArray<id> *datas;

/// 转换的block 当列数据的元素不是`NSString`类型时，需设置此block
@property (nonatomic, copy) NSString *(^transformBlock)(id value);

/// 选中的值
@property (nonatomic, strong) id selectedValue;
/// 选中的索引序号
@property (nonatomic, assign) NSInteger selectedIndex;
/// 上次选中的值
@property (nonatomic, strong, readonly) id lastSelectedValue;
/// 上次选中的索引号
@property (nonatomic, assign, readonly) NSInteger lastSelectedIndex;

@end


#pragma mark -
/// 静态选择器 适合于无联动
@interface LYStaticPicker : LYPickerView

/// 模型数组
@property (nonatomic, strong) NSArray<LYColumnData *> *datas;

- (void)setDatas:(NSArray<LYColumnData *> *)datas
        animated:(BOOL)animated;

- (BOOL)selectValue:(NSString *)value
        inComponent:(NSInteger)component
           animated:(BOOL)animated;

- (BOOL)selectValue:(NSString *)value
        inComponent:(NSInteger)component
           animated:(BOOL)animated
       needCallback:(BOOL)needed;

- (NSUInteger)rowInComponent:(NSInteger)component
                 passingTest:(BOOL(^)(id value, NSString *title, NSUInteger idx))block;

- (void)setColumsSelectedValueDidChangeBlock:(void(^)(__kindof LYPickerView *view))block;

#pragma mark Subclass Override
- (void)didSelectRowForColumnData:(LYColumnData *)data;

@end





